package com.sichen.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class SichenCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        //所有请求
        configuration.addAllowedHeader("*");
        //允许那些请求方式跨域
        configuration.addAllowedMethod("*");
        //允许那些请求来源进行跨域
        configuration.addAllowedOrigin("*");
        //是否允许携带cookie跨域
        configuration.setAllowCredentials(true);
        //配置跨域参数
        source.registerCorsConfiguration("/**",configuration);
        return new CorsWebFilter(source);
    }
}
